<?php $this->headTitle('Truyện cười - index'); ?>
<a href="<?php echo $this->baseUrl("/index/login"); ?>">Đăng nhập</a>
|
<a href="<?php echo $this->baseUrl("/index/registry"); ?>">Đăng kí</a>
|
<a href="<?php echo $this->baseUrl("/index/index"); ?>">Trang chủ</a>
| Trang
<?php
$tbStorys = new Default_Model_Storys();
$prefix = Zend_Registry::get('prefix');
$select = $tbStorys->select()
                ->from(array('p' => $prefix . 'Storys'),
                        array('p.Category'))->distinct();
$smt = $select->query();
$res = $smt->fetchAll();
if (!isset($_GET['category']))
    $category = $res[0]['Category'];

else
    $category= $_GET['category'];

$totalRecord = $tbStorys->fetchAll("Category = '$category'")->count();
$recordPerPage = 5;
$numberPage = $totalRecord / $recordPerPage;
if (!isset($_GET['page']))
    $page = 1;
else
    $page = $_GET['page'];
if ($totalRecord % $recordPerPage != 0)
    $numberPage++;
for ($i = 1; $i <= $numberPage; $i++) {
    if ($i != $page)
        echo '<a href="?category=' . $category . '&page=' . $i . '">[' . $i . ']</a>';
    else
        echo "[$i]";
}
echo "<br/>";
foreach ($res as $value) {
    if ($value['Category'] == $category)
        echo '[' . $value['Category'] . ']';
    else
        echo '<a href="?category=' . $value['Category'] . '">[' . $value['Category'] . ']</a>';
}
$storys = $tbStorys->fetchAll("Category = '$category'", "StoryId desc", $recordPerPage, ($page - 1) * $recordPerPage);
$count = 0;
foreach ($storys as $value) {
    $count++;
    echo "<br/><b>$count. " . $value['Title'] . "</b><br/>";
    echo "Thể loại: " . $value['Category'] . "<br/>";
    echo "Thời gian: " . $value['PostTime'] . "<br/>";
    echo "Tác giả: [" . $value['Author'] . "]<br/>";
    echo '<b><span style="color:#F00">' . $value['Content'] . '</span></b><br/>';
}
echo 'Trang ';
for ($i = 1; $i <= $numberPage; $i++) {
    if ($i != $page)
        echo '<a href="?category=' . $category . '&page=' . $i . '">[' . $i . ']</a>';
    else
        echo "[$i]";
}
echo "<br/>";
foreach ($res as $value) {
    if ($value['Category'] == $category)
        echo '[' . $value['Category'] . ']';
    else
        echo '<a href="?category=' . $value['Category'] . '">[' . $value['Category'] . ']</a>';
}
?>